webUtils.nameSpace("wiseMen.platform");
wiseMen.platform.initProperties={
		adminDiv:{
			name:"广东省",
			code:"440000"
		}	
	};
wiseMen.platform.mainPage = function (params) {
    var me = this, contentObj, menuBarObj,navToolbarObj,contentViewObj;

    var cfg = {
        menuBarDomId: "#menuNavBar",
        navToolbarDomId:"#navToolbar",
        contentViewDomId:"#contentView"
    };
    //布局
    var layout = function () {
        /*
        contentObj.layout({
            border:false
        });
        */
        menuBarObj = contentObj.find(cfg.menuBarDomId);
        contentViewObj=contentObj.find(cfg.contentViewDomId);
    };
    //初始化菜单
    var initMenu = function () {
    	
    	var sidebarMenu=$("#sidebar-menu");
    	
    	function rendererMenu(menuList){
            $.each(menuList, function (i, n) {
            	var menuTemp1='<li>'
            			+'<a href="javascript:void(0)">'
            			+'<i class="'+(n.iconCss?n.iconCss:'fa fa-link')+'"></i>'
            			+'<span>'+n.name+'</span>'
            			+'</a>'
            			+'</li>';
            	var menuTemp2='<li class="treeview">'
        			+'<a href="javascript:void(0)">'
        			+'<i class="'+(n.iconCss?n.iconCss:'fa fa-link')+'"></i>'
        			+'<span>'+n.name+'</span>'
        			+'<i class="fa fa-angle-left pull-right"></i>'
        			+'</a>'
        			+'<ul class="treeview-menu"></ul>'
        			+'</li>';
            	if(n.childrenSize<=0){
            		var $menuTemp1=$(menuTemp1);
            		$menuTemp1.data("menuData",n);
            		sidebarMenu.append($menuTemp1);
            	}else{
            		var $menuTemp2=$(menuTemp2);
            		sidebarMenu.append($menuTemp2);
            		var treeviewMenu=$menuTemp2.find(".treeview-menu");
            		$.each(n.subMenus,function(subI,subN){
            			var subMenuTemp='<li>'
            						+'<a href="javascript:void(0)"><i class="fa fa-circle-o"></i> '+subN.name+'</a>'
            						+'</li>';
            			var $subMenuTemp=$(subMenuTemp);
            			$subMenuTemp.data("menuData",subN);
            			treeviewMenu.append($subMenuTemp);
            		})
            	}
            	
            });
            
            var firstLi=sidebarMenu.find("li:eq(1)");
            var firstMenu=null;
            if(firstLi.is(".treeview")){
            	firstMenu=firstLi.find(".treeview-menu li:eq(0) a");
            }else{
            	firstMenu=firstLi.find("a");
            }
            if(firstMenu){
            	firstMenu.click();
            }
        }
    	
    	for(var i=0; i<params.sysCode.length; i++){
    		 webUtils.getUserSubMenuById('-1',params.sysCode[i],rendererMenu,true);
    	}
    	
        webUtils.on("sideBar.menu.click",function(obj){
        	if(!obj.menu.is(".active")){
        		$(obj.menuSelector+" li").removeClass("active");
        		obj.menu.addClass("active");
        	}
        	var menuData=obj.menu.data("menuData");
        	if(menuData && menuData.funcPoint){
        		webUtils.triggerOnMenu(menuData,contentViewObj);
        		
        		$("#page-header").html(menuData.name);
        		$("#page-here").html(menuData.name);
        	}
        });
        
    };
    var menuClick = function () {
        var menuData=$(this).data("menuData");
        if(menuData.funcPoint){
            webUtils.triggerOnMenu(menuData,contentViewObj);
        }
    };
    
    var initEvent=function(){
    	//处理键盘事件 禁止后退键（Backspace）密码或单行、多行文本框除外
        function forbidBackSpace(e) {
            var ev = e || window.event; //获取event对象 
            var obj = ev.target || ev.srcElement; //获取事件源 
            var t = obj.type || obj.getAttribute('type'); //获取事件源类型 
            //获取作为判断条件的事件类型 
            var vReadOnly = obj.readOnly;
            var vDisabled = obj.disabled;
            //处理undefined值情况 
            vReadOnly = (vReadOnly == undefined) ? false : vReadOnly;
            vDisabled = (vDisabled == undefined) ? true : vDisabled;
            //当敲Backspace键时，事件源类型为密码或单行、多行文本的， 
            //并且readOnly属性为true或disabled属性为true的，则退格键失效 
            var flag1 = ev.keyCode == 8 && (t == "password" || t == "text" || t == "textarea") && (vReadOnly == true || vDisabled == true);
            //当敲Backspace键时，事件源类型非密码或单行、多行文本的，则退格键失效 
            var flag2 = ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea";
            //判断 
            if (flag2 || flag1) return false;
        }
        //禁止后退键 作用于Firefox、Opera
        document.onkeypress = forbidBackSpace;
        //禁止后退键  作用于IE、Chrome
        document.onkeydown = forbidBackSpace;
        
        $(".user-menu .dropdown-menu").on("click", function(e) {
		    e.stopPropagation();
		});
        
        $(".editCurrentUserBt").click(function(){
        	var u=webUtils.getCurrentUser();
        	editUserInfoPanelContent({
        		id:u.id
        	});
        });
    };
    var initUserInfo=function(){
    	var u=webUtils.getCurrentUser();
    	
    	$(".current-user-name").html(u.userName);
    	if(u.currentOrg){
    		$(".current-org-name").html(u.currentOrg.fullName);
    	}
    	$(".current-date").html(webUtils.parseTimestamp(new Date()));
    };
    
    function editUserInfoPanelContent(params) {
    	params = params || {};
        var t = [];
        if (params.id) {
            t.push("id=" + params.id);
        }
        if (params.orgId) {
            t.push("orgId=" + params.orgId);
        }
        var sub = top.webUtils.topicSubscribe("user.edit.success", function (args) {
    		dialog.close();
    		window.location.href=ctx;
        });
        var dialog=webUtils.dialog({
	       	 title:'编辑用户信息',
	       	 url:ctx + '/userAction/editPersonalView.do?' + t.join("&"),
	       	 onremove:function () {
	       		sub.remove();
	         }
        });
        return dialog;
    }
    //全局初始化
    var int = function () {
        contentObj = $("body");
        layout();
        initMenu();
        initUserInfo();
        initEvent();
    }();
    
    
};

